/*******************************************************************************
 * Copyright (c) 2009-2011 ETCORE Labs. All rights reserved. 
 * 
 * This software is the confidential and proprietary information of ETCORE Labs.
 * You shall not disclose such confidential information and shall use it
 * only in accordance with the terms of the license agreement you entered into
 * with ETCORE Labs. 
 * 
 * Support can be obtained from support forums at:  http://www.etcore.com/
 * /
 *******************************************************************************/
package etcore.webapp.grouptalk.common.service;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;

import etcore.webapp.grouptalk.common.dao.GroupDirectoryRelationshipDAO;
import etcore.webapp.grouptalk.common.dao.HibernateSessionFactory;
import etcore.webapp.grouptalk.common.object.GroupDirectoryRelationship;

/**
 * GroupDirectoryRelationshipService implements queries and transactions on
 * GroupDirectoryRelationship
 * 
 * @author ETCORE GroupTalk Developers
 * 
 */
public class GroupDirectoryRelationshipService extends BaseService {

	public GroupDirectoryRelationship findById(java.lang.Integer id) {
		Session session = HibernateSessionFactory.getSession();
		try {
			GroupDirectoryRelationshipDAO dao = new GroupDirectoryRelationshipDAO();
			GroupDirectoryRelationship result = dao.findById(id);

			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	public List<GroupDirectoryRelationship> findByGidAndDid(
			java.lang.Integer gid, Integer did) {
		Session session = HibernateSessionFactory.getSession();
		try {
			GroupDirectoryRelationshipDAO dao = new GroupDirectoryRelationshipDAO();
			List<GroupDirectoryRelationship> result = dao.findByGidAndDid(gid,
					did);

			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	public List<GroupDirectoryRelationship> findByProperty(String propertyName,
			Object value, int begin, int length) {
		Session session = HibernateSessionFactory.getSession();
		try {
			GroupDirectoryRelationshipDAO dao = new GroupDirectoryRelationshipDAO();
			List<GroupDirectoryRelationship> result = dao.findByProperty(
					propertyName, value, begin, length);

			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	public void deleteByProperty(String propertyName, Object value) {
		Session session = HibernateSessionFactory.getSession();
		Transaction tx = session.beginTransaction();
		try {
			GroupDirectoryRelationshipDAO dao = new GroupDirectoryRelationshipDAO();
			List<GroupDirectoryRelationship> results = dao.findByProperty(
					propertyName, value);
			dao.deleteSingle(results);
			tx.commit();
		} catch (RuntimeException re) {
			tx.rollback();
			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	public List<GroupDirectoryRelationship> findByProperty(String propertyName,
			Object value) {
		Session session = HibernateSessionFactory.getSession();
		try {
			GroupDirectoryRelationshipDAO dao = new GroupDirectoryRelationshipDAO();
			List<GroupDirectoryRelationship> result = dao.findByProperty(
					propertyName, value);

			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	public long findSizeByProperty(String propertyName, Object value) {
		Session session = HibernateSessionFactory.getSession();
		try {
			GroupDirectoryRelationshipDAO dao = new GroupDirectoryRelationshipDAO();
			long result = dao.findSizeByProperty(propertyName, value);

			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	public List<GroupDirectoryRelationship> findAll(int begin, int length) {
		Session session = HibernateSessionFactory.getSession();
		try {
			GroupDirectoryRelationshipDAO dao = new GroupDirectoryRelationshipDAO();
			List<GroupDirectoryRelationship> result = dao
					.findAll(begin, length);

			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

}